/*
 * 8.5.cpp 1054_poj
 *
 *  Created on: 2012-5-21
 *      Author: jawinton
 */

#include <cstring>
#include <cstdio>
#include <cstdlib>

#define SIZE 5001

struct PLANT {
	int x;
	int y;
};
PLANT plants[SIZE];
int row, col, n;

int compare (const void * a, const void *b) {
	PLANT *elem1 = (PLANT *)a, *elem2 = (PLANT *)b;
	if (elem1->x == elem2->x) return elem1->y - elem2->y;
	else return elem1->x - elem2->x;
}

int searchPath (PLANT secPlant, int stepX, int stepY) {
	PLANT plant;
	plant.x = secPlant.x + stepX;
	plant.y = secPlant.y + stepY;
	int steps = 2;
	while (plant.x<=row && plant.y <= col && plant.x>=1 && plant.y>=1) {
		/*int left = 0, right = n-1;
		int mid;
		while (left <= right) {
			mid = (left+right)/2;
			int compareResult = compare(&plant, &plants[mid]);
			if (compareResult == 0) {
				steps++;
				plant.x += stepX;
				plant.y += stepY;
				break;
			} else if (compareResult < 0) {
				right = mid - 1;
				continue;
			} else {
				left = mid + 1;
				continue;
			}
		}
		if (left > right) {
			steps = 0;
		}*/
		if (!bsearch(&plant, plants, n, sizeof(PLANT), compare)) {
			steps = 0;
			break;
		}
		plant.x += stepX;
		plant.y += stepY;
		steps++;
	}
	return steps;
}

int main (void) {
	int max = 2;
	scanf("%d %d", &row, &col);
	scanf("%d", &n);
	for (int i=0; i<n; i++)
		scanf("%d %d", &plants[i].x, &plants[i].y);
	qsort(plants, n, sizeof(PLANT), compare);
	for (int i=0; i<n-2; i++) {
		for (int j=i+1; j<n-1; j++) {
			int stepX = plants[j].x - plants[i].x;
			int stepY = plants[j].y - plants[i].y;
			PLANT prePlant;
			prePlant.x = plants[i].x - stepX;
			prePlant.y = plants[i].y - stepY;
			if (prePlant.x<=row && prePlant.x>=1 && prePlant.y<=col && prePlant.y>=1)
				continue;
			if (plants[i].x+max*stepX > row)
				break;
			if (plants[i].y+max*stepY > col || plants[i].y+max*stepY < 1)
				continue;
			int tmpStep = searchPath(plants[j], stepX, stepY);
			if (tmpStep > max) max = tmpStep;
		}
	}
	if (max == 2) max = 0;
	printf("%d\n", max);
	return 0;
}
